package com.meirimoney.app.control;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.meirimoney.app.R;

public class HeadControl extends BaseLinearLayout implements Navigation,
		OnClickListener, android.content.DialogInterface.OnClickListener {

	public HeadControl(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.activityContext = context;
		((LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
				R.layout.mrm_head, this, true);
		this.guideView = ((LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
				R.layout.mrm_guid_integral, null);
		this.title = (TextView) this.findViewById(R.id.title);
		this.guide = (Button) this.findViewById(R.id.guide);
		this.guide.setOnClickListener(this);

	}

	public String getTitle() {
		return this.title.getText().toString();
	}

	public void setTitle(String title) {
		this.title.setText(title);
	}

	private Context activityContext;

	private TextView title;

	private Button guide;

	private View guideView;

	private AlertDialog dialog;

	@Override
	public void onClick(DialogInterface dialog, int which) {
		dialog.dismiss();
	}

	@Override
	public void onClick(View v) {
		if (null != this.dialog) {
				this.dialog.dismiss();
				this.dialog.show();
		} else {
			Builder builder = new Builder(HeadControl.this.activityContext);
			builder.setTitle("每日赚新手指南");
			builder.setView(HeadControl.this.guideView);
			builder.setPositiveButton("知道了", this);
			this.dialog = builder.create();
			dialog.show();
		}
	}
}
